/*
 * Email Notify
 * Author: Antonio Nastasi
 * Email: sifcenter (at) gmail.it
 * Version: 0.1
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef EMAILNOTIFY_HEADER
#define EMAILNOTIFY_HEADER

#include <KIcon> 
#include <Plasma/Applet>
#include <Plasma/Svg>
#include <QSslSocket>
#include <QTimer>
#include <Phonon/MediaObject>
#include <ConfigDialog.h>


class EmailNotify : public Plasma::Applet
{
    Q_OBJECT
    public:
       
        EmailNotify(QObject *parent, const QVariantList &args);
        ~EmailNotify(); 
       
        void paintInterface(QPainter *painter,
                const QStyleOptionGraphicsItem *option,
                const QRect& contentsRect);
	void init();
 
    private:
	enum CommandType {LOGIN,PASSWORD,STAT};
	enum ConnectionState {NO_CONNECTED, CONNECTED, VERIFY_USER, VERIFY_PASSWORD, CMD_STAT};
	ConnectionState state;
	
	QSslSocket socket;
        Plasma::Svg m_svg;
	void sendMessage(CommandType);
	void checkConfig();
        KIcon m_icon;	
	QString text;
	KConfig *config;
	KConfigGroup *generalGroup;
	QTimer *timer;	
	// For play sound
	Phonon::MediaObject *media;	
	
	int currentEmails;
	// For Configure Dialog	
	ConfigDialog configDialog;
	
	
	
	
	// Values
	QString login,password,sound_file,server;
	int interval,port,ssl;
	
    private slots:
	void checkIfConnected();
	void showConfigurationInterface();
	void connectAndCheck();
	void socketEncrypted();
	void socketConnected();
	void getMessage();
	void playSound();	
	void errorConnection(QAbstractSocket::SocketError);
	
};

K_EXPORT_PLASMA_APPLET(emailnotify, EmailNotify)
#endif
